/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/crypto/cryptoTwoFish.cpp,v 1.2 2003/11/21 12:39:24 itsme Exp $
 *
 *
 *  wrapper class around TwoFish implementation in machine\spcore\crypto.c
 *
 *  only used to verify the correct functioning of the algorithm
 *
 *  code to verify the correct functioning of this module is in cryptoVerifier.cpp
 *
 */
#include "crypto.h" // from the spcore directory

#include "CryptoTwoFish.h"

CryptoTwoFish::CryptoTwoFish()
{
    ClearKey();
}

CryptoTwoFish::~CryptoTwoFish()
{
    ClearKey();
}


void CryptoTwoFish::ClearKey()
{
    ByteVector key(8*4);
    SetKey(key);
}

bool CryptoTwoFish::SetKey(const ByteVector& key)
{
    if (key.size()!=CryptoTwoFish::KEYSIZE)
        return false;

    m_key= key;

    crypto_twofish_setup(&m_state, (DWORD*)vectorptr(key));

    return true;
}

const ByteVector& CryptoTwoFish::GetKey() const
{
    return m_key;
}

ByteVector CryptoTwoFish::Encrypt(const ByteVector& plain)
{
    ByteVector result(CryptoTwoFish::BLOCKSIZE);
    crypto_twofish_encrypt(&m_state, (const DWORD*)vectorptr(plain), (DWORD*)vectorptr(result));
    return result;
}

